<?php
require_once 'Artdepot/ImageHelper.php';
class Model_Artist extends Zend_Db_Table_Row
{
	public function getPhotoPhysicalPath($size=null) {
		$origFile = PUBLIC_PATH . '/images/artists_avar/' . $this->photo;
		if (empty($size)) {
			return $origFile;
		}
		$resizedFile = PUBLIC_PATH . '/images/artists_avar/' . $size . '_' . $this->photo;
		if (!file_exists($resizedFile) && is_readable($origFile)) {
			ImageHelper::resize($origFile, $resizedFile, $size);
		}
		return $resizedFile;
	}
	
	public function getPhotoWebAccessablePath($size=null) {
		if (empty($size)) {
			return '/images/artists_avar/' . $this->photo;
		}
		$this->getPhotoPhysicalPath($size);
		return '/images/artists_avar/' . $size . '_' . $this->photo;
	}
	
	public function getCriticises() {
		$criticiseTable = new Model_DbTable_Criticise();
        return $criticiseTable->getAllByArtist($this->id);
	}
	
	/**
	 * if null gave, returns all typical artworks of current artist
	 * @param int $num
	 * @return Zend_Db_Table_Rowset
	 */
	public function getTypicalArtworks($num=null){
		$num = (int) $num;
		
		$table = new Model_DbTable_ArtWork();
		if ($num > 0) {
			$artworks = $table->fetchAll("artist = $this->id AND typical= 'Y'", null, $num);
		}else{
			$artworks = $table->fetchAll("artist = $this->id AND typical= 'Y'");
		}
		
		return $artworks;
	}
	
	public function getArtworks(){
		$table = new Model_DbTable_ArtWork();
		$artworks = $table->fetchAll("artist = $this->id");
		
		return $artworks;
	}
}

